home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Produtividade / OpenOffice.org 2.0.1 / openofficeorg1.cab / ShowDialog.js < prev    next >
Text File  |  2004-10-22  |  4KB  |  116 lines

  1. importClass(Packages.com.sun.star.uno.UnoRuntime);
  2. importClass(Packages.com.sun.star.lang.XMultiComponentFactory);
  3. importClass(Packages.com.sun.star.awt.XDialogProvider);
  4. importClass(Packages.com.sun.star.awt.XDialog);
  5. importClass(Packages.com.sun.star.uno.Exception);
  6. importClass(Packages.com.sun.star.script.provider.XScriptContext);
  7.  
  8. importClass(java.lang.Thread);
  9. importClass(java.lang.System);
  10.  
  11. function tryLoadingLibrary( xmcf, context, name )
  12. {
  13.     try 
  14.     {
  15.         obj = xmcf.createInstanceWithContext(
  16.                "com.sun.star.script.Application" + name + "LibraryContainer",
  17.                context.getComponentContext());
  18.  
  19.         xLibraryContainer = UnoRuntime.queryInterface(XLibraryContainer, obj);
  20.  
  21.         System.err.println("Got XLibraryContainer");
  22.  
  23.         serviceObj = context.getComponentContext().getValueByName(
  24.                     "/singletons/com.sun.star.util.theMacroExpander");
  25.  
  26.         xme = AnyConverter.toObject(new Type(XMacroExpander), serviceObj);
  27.  
  28.         bootstrapName = "bootstraprc";
  29.         if (System.getProperty("os.name").startsWith("Windows")) 
  30.         {
  31.             bootstrapName = "bootstrap.ini";
  32.         }
  33.  
  34.         libURL = xme.expandMacros(
  35.                 "${$SYSBINDIR/" + bootstrapName + "::BaseInstallation}" +
  36.                     "/share/basic/ScriptBindingLibrary/" +
  37.                     name.toLowerCase() + ".xlb/");
  38.  
  39.         System.err.println("libURL is: " + libURL);
  40.  
  41.         xLibraryContainer.createLibraryLink(
  42.             "ScriptBindingLibrary", libURL, false);
  43.  
  44.         System.err.println("liblink created");
  45.  
  46.     } 
  47.     catch (e) 
  48.     {
  49.         System.err.println("Got an exception loading lib: " + e.getMessage());
  50.         return false;
  51.     }
  52.     return true;
  53. }
  54.  
  55. function getDialogProvider()
  56. {
  57.     // UNO awt components of the Highlight dialog
  58.     //get the XMultiServiceFactory
  59.     xmcf = XSCRIPTCONTEXT.getComponentContext().getServiceManager();
  60.  
  61.     args = new Array;
  62.     //get the XDocument from the context
  63.     args[0] = XSCRIPTCONTEXT.getDocument();
  64.  
  65.     //try to create the DialogProvider
  66.     try {
  67.         obj = xmcf.createInstanceWithArgumentsAndContext(
  68.             "com.sun.star.awt.DialogProvider", args,
  69.             XSCRIPTCONTEXT.getComponentContext());
  70.     }
  71.     catch (e) {
  72.         System.err.println("Error getting DialogProvider object");
  73.         return null;
  74.     }
  75.  
  76.     return UnoRuntime.queryInterface(XDialogProvider, obj);
  77. }
  78.  
  79. //get the DialogProvider
  80. xDialogProvider = getDialogProvider();
  81.  
  82. if (xDialogProvider != null)
  83. {
  84.     //try to create the Highlight dialog (found in the ScriptBinding library)
  85.     try 
  86.     {
  87.         findDialog = xDialogProvider.createDialog("vnd.sun.star.script:" +
  88.             "ScriptBindingLibrary.Highlight?location=application");
  89.         if( findDialog == null )
  90.         {
  91.             if (tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Dialog") == false ||
  92.                 tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Script") == false)
  93.             {
  94.                 System.err.println("Error loading ScriptBindingLibrary");
  95.             }
  96.             else
  97.             {
  98.                 // try to create the Highlight dialog (found in the 
  99.                 // ScriptBindingLibrary)
  100.                 findDialog = xDialogProvider.createDialog("vnd.sun.star.script:" +
  101.                     "ScriptBindingLibrary.Highlight?location=application");
  102.             }
  103.         }
  104.  
  105.         //launch the dialog
  106.         if ( findDialog != null )
  107.         {
  108.             findDialog.execute();
  109.         }
  110.     }
  111.     catch (e) {
  112.         System.err.println("Got exception on first creating dialog: " +
  113.             e.getMessage());
  114.     }
  115. }
  116.